/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taganalysistoolsclient;

import elaborate.tag_analysis.model.User;
import elaborate.tag_analysis.restws.client.UserDao;
import java.util.List;
import java.util.UUID;

/**
 *
 * @author lendle
 */
public class TagAnalysisToolsClient {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        // TODO code application logic here
        UserDao dao=new UserDao("http://taganalysis.appspot.com/rest/user");
        User user=new User();
        user.setApplicationId("1");
        user.setId(UUID.randomUUID().toString());
        dao.newUser(new User[]{user});
        user.setName("hahaha");
        dao.updateResource(user);
        dao.deleteResource("1", user.getId());
        List<User> users=dao.findAll("1");
        System.out.println(users.size());
        user=dao.findById("1", "adfe8548-99da-4661-9091-8d9164781d58");
        System.out.println(user);
//        ClientConfig config = new DefaultClientConfig();
//        Client client = Client.create(config);
//        WebResource service = client.resource("http://taganalysis.appspot.com");
//        Form form = new Form();
//        form.add("id", ""+UUID.randomUUID().toString());
//        form.add("name", "test1");
//        form.add("applicationId", "1");
//        ClientResponse response = service.path("rest").path("user").accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, form);
//        User user=response.getEntity(User.class);
//        user.setName("hahaha");
//        service.path("rest").path("user").accept(MediaType.APPLICATION_JSON).put(User.class, user);
//        service.path("rest").path("user").path("1").path(URLEncoder.encode(""+user.getId(), "utf-8")).delete();
//        response= service.path("rest").path("user").path("1").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
//        User [] users=response.getEntity(User[].class);
//        System.out.println(users.length);
//        response= service.path("rest").path("user").path("1").path("adfe8548-99da-4661-9091-8d9164781d58").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
//        System.out.println(response.getEntity(User.class).getName());
    }
}
